﻿@{
    ViewBag.Title = "Closure";
    Layout = "~/Views/Shared/_Page.cshtml";
}

<h2>Closure</h2>
<br />
<h3>Path: @ViewBag.Path</h3>
<br />
<h3>See the result on console</h3>
<br />

<script type="text/javascript">
    function calculateArea(height, width, shape) {
        var pi = Math.PI;

        //first closure
        function getCircleArea() {
            var circleArea = pi * (height * height);
            return circleArea;
        }

        //second closure
        function getRectangleArea() {
            var area = width * height;
            return area;
        }

        if (shape === 'Circle') {
            return getCircleArea();
        }
        else {
            return getRectangleArea();
        }
    }

    window.onload = function () {
        ZEUS.DEBUG.log('Circle Area: ' + calculateArea(10, 8, 'Circle'));
        ZEUS.DEBUG.log('Rectangle Area: ' + calculateArea(10, 8, 'Rectangle'));
    }
</script>
